package com.basketball.core.exception;

import com.basketball.core.domain.ResultBean;
import com.basketball.core.enmu.ErrorEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理器
 * @author xzx
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 自定义异常
     * @param e
     * @return
     */
    @ExceptionHandler(value = BusinessException.class)
    public  @ResponseBody ResultBean  businessExceptionHandler(BusinessException e){
        log.error(e.getErrorMsg(),e);
        return ResultBean.businessException(e);
    }

    /**
     * RunTime
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public @ResponseBody ResultBean runTimeException(Exception e){
        log.error(e.getMessage(),e);
        return ResultBean.runTimeException(ErrorEnum.INTERNAL_SERVER_ERROR);
    }


}
